package cn.ecasoft.common.message.core;

import cn.ecasoft.common.message.IJson;
import com.alibaba.fastjson.JSON;

import java.lang.reflect.Type;

/**
 * create by getui on 2020/9/25
 *
 * @author getui
 */
public class DefaultJson implements IJson {

    @Override
    public String toJson(Object obj) {
        if (obj == null) {
            return null;
        }
        return JSON.toJSONString(obj);
    }

    @Override
    public <T> T fromJson(String jsonString, Type type) {
        return JSON.parseObject(jsonString, type);
    }

    @Override
    public <T> T fromJson(String jsonString, Class<T> tClass) throws Exception {
        return JSON.parseObject(jsonString, tClass);
    }

}
